﻿namespace mVids
{
    using MediaPortal.Configuration;
    using MediaPortal.Profile;
    using MediaPortal.ServiceImplementations;
    using mVids.Properties;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.IO;
    using System.Windows.Forms;

    public class dbManager : Form
    {
        private ToolStripMenuItem addManualToolStripMenuItem;
        private Button button2;
        private IContainer components = null;
        private string currArtist;
        private string currFilename;
        private mVids.database db = new mVids.database();
        private Panel detailsPanel;
        private ComboBox filterFieldbox;
        private ComboBox filterSelectBox;
        private TextBox filterTextBox;
        private ContextMenuStrip imageContext;
        private Label label9;
        private MenuStrip menuStrip1;
        private OpenFileDialog openFileDialog1;
        private PictureBox pictureBox1;
        private PictureBox pictureBox2;
        private Button showAllbtn;
        private string thumbdir = Config.GetFolder(Config.Dir.Thumbs);
        private List<string> treeArtists = new List<string>();
        private TreeView treeView1;

        public dbManager()
        {
            this.InitializeComponent();
        }

        private void addManualToolStripMenuItem_Click(object sender, EventArgs e)
        {
            mVids.addManual manual = new mVids.addManual();
            Settings settings = new Settings(Config.GetFolder(Config.Dir.Config) + "/MediaPortal.xml", true);
            string str = settings.GetValue("mvid", "basepath");
            List<string> files = new List<string>();
            foreach (string str2 in str.Split("|".ToCharArray()))
            {
                if (Directory.Exists(str2))
                {
                    string[] collection = Directory.GetFiles(str2);
                    files.AddRange(collection);
                }
            }
            manual.setupWindow(files, this.db.getFiles(), this.db.getArtists());
            manual.ShowDialog();
            this.treeView1.Nodes.Clear();
            this.loadTreeViewItems(new List<mVids.artist>(), true);
            settings.Dispose();
        }

        private void aUC_Disposed(object sender, EventArgs e)
        {
            this.loadTreeViewItems(null, true);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            mVids.artistInfo info = new mVids.lastFM().getArtistInfo(this.db.getArtistInfo(this.treeView1.SelectedNode.Text));
            this.detailsPanel.Controls.Clear();
            mVids.artistUC tuc = new mVids.artistUC(this.db, info.name, info.lfmName, info.tags, info.bioSummary, info.bioContent);
            this.detailsPanel.Controls.Add(tuc);
            MessageBox.Show("Information synched with last.fm", "Success", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
        }

        private void clearFields(bool isArtist)
        {
            if (isArtist)
            {
                this.imageContext.Items.Add("Import Artist Image");
            }
            else if (!isArtist)
            {
                this.imageContext.Items.Add("Regrab Video Thumbnail");
            }
        }

        private void dbManager_Load(object sender, EventArgs e)
        {
            this.loadTreeViewItems(new List<mVids.artist>(), true);
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void filter_changed(object sender, EventArgs e)
        {
            if (((this.filterSelectBox.SelectedItem != null) && (this.filterFieldbox.SelectedItem != null)) && (this.filterTextBox.Text != null))
            {
                Log.Debug("Music Video DB - filterSelectBox={0}, filterFieldbox={1}, filterTextbox={2}", new object[] { this.filterSelectBox.SelectedItem.ToString(), this.filterFieldbox.SelectedItem.ToString(), this.filterTextBox.Text });
                switch (this.filterFieldbox.SelectedItem.ToString())
                {
                    case "Artist":
                        this.filterByArtist();
                        break;

                    case "Song":
                        this.filterBySong();
                        break;

                    case "Filename":
                        this.filterByFilename();
                        break;

                    case "Rating":
                        this.filterByRating();
                        break;

                    case "Play Count":
                        this.filterByPlayCount();
                        break;

                    case "Score":
                        this.filterByScore();
                        break;

                    case "Length":
                        this.filterByLength();
                        break;

                    case "Biography (Summary)":
                        this.filterBySummary();
                        break;

                    case "Biography (Full)":
                        this.filterByContent();
                        break;

                    case "Tags":
                        this.filterByTags();
                        break;
                }
            }
        }

        private void filterByArtist()
        {
            List<mVids.artist> list = this.db.getArtistsAndBios(true);
            List<mVids.artist> artists = new List<mVids.artist>();
            string str = this.filterSelectBox.SelectedItem.ToString();
            if (str != null)
            {
                if (!(str == "="))
                {
                    if (str == "Contains")
                    {
                        artists = new List<mVids.artist>();
                        foreach (mVids.artist artist in list)
                        {
                            if (artist.artistName.Contains(this.filterTextBox.Text))
                            {
                                artists.Add(artist);
                            }
                        }
                        this.loadTreeViewItems(artists, false);
                    }
                }
                else
                {
                    artists = new List<mVids.artist>();
                    foreach (mVids.artist artist in list)
                    {
                        if (artist.artistName == this.filterTextBox.Text)
                        {
                            artists.Add(artist);
                        }
                    }
                    this.loadTreeViewItems(artists, false);
                }
            }
        }

        private void filterByContent()
        {
            List<mVids.artist> list = this.db.getArtistsAndBios(false);
            List<mVids.artist> artists = new List<mVids.artist>();
            string str = this.filterSelectBox.SelectedItem.ToString();
            if (str != null)
            {
                if (!(str == "="))
                {
                    if (str == "Contains")
                    {
                        artists = new List<mVids.artist>();
                        foreach (mVids.artist artist in list)
                        {
                            if (artist.bio.Contains(this.filterTextBox.Text))
                            {
                                artists.Add(artist);
                            }
                        }
                        this.loadTreeViewItems(artists, false);
                    }
                }
                else
                {
                    artists = new List<mVids.artist>();
                    foreach (mVids.artist artist in list)
                    {
                        if (artist.bio == this.filterTextBox.Text)
                        {
                            artists.Add(artist);
                        }
                    }
                    this.loadTreeViewItems(artists, false);
                }
            }
        }

        private void filterByFilename()
        {
            List<mVids.musicVideo> list = this.db.getSongs();
            List<mVids.musicVideo> songs = new List<mVids.musicVideo>();
            string str = this.filterSelectBox.SelectedItem.ToString();
            if (str != null)
            {
                if (!(str == "="))
                {
                    if (str == "Contains")
                    {
                        foreach (mVids.musicVideo video in list)
                        {
                            if (video.Path.Contains(this.filterTextBox.Text))
                            {
                                songs.Add(video);
                            }
                        }
                        this.loadTreeViewItems(songs);
                    }
                }
                else
                {
                    foreach (mVids.musicVideo video in list)
                    {
                        if (video.Path == this.filterTextBox.Text)
                        {
                            songs.Add(video);
                        }
                    }
                    this.loadTreeViewItems(songs);
                }
            }
        }

        private void filterByLength()
        {
            List<mVids.musicVideo> list = this.db.getSongs();
            List<mVids.musicVideo> songs = new List<mVids.musicVideo>();
            string str = this.filterSelectBox.SelectedItem.ToString();
            if (str != null)
            {
                if (!(str == "="))
                {
                    if (str == "Contains")
                    {
                        foreach (mVids.musicVideo video in list)
                        {
                            if (video.Duration.ToString().Contains(this.filterTextBox.Text))
                            {
                                songs.Add(video);
                            }
                        }
                        this.loadTreeViewItems(songs);
                    }
                }
                else
                {
                    foreach (mVids.musicVideo video in list)
                    {
                        if (video.Duration.ToString() == this.filterTextBox.Text)
                        {
                            songs.Add(video);
                        }
                    }
                    this.loadTreeViewItems(songs);
                }
            }
        }

        private void filterByPlayCount()
        {
            List<mVids.musicVideo> list = this.db.getSongs();
            List<mVids.musicVideo> songs = new List<mVids.musicVideo>();
            string str = this.filterSelectBox.SelectedItem.ToString();
            if (str != null)
            {
                if (!(str == "="))
                {
                    if (str == "Contains")
                    {
                        foreach (mVids.musicVideo video in list)
                        {
                            if (video.playcount.Contains(this.filterTextBox.Text))
                            {
                                songs.Add(video);
                            }
                        }
                        this.loadTreeViewItems(songs);
                    }
                }
                else
                {
                    foreach (mVids.musicVideo video in list)
                    {
                        if (video.playcount == this.filterTextBox.Text)
                        {
                            songs.Add(video);
                        }
                    }
                    this.loadTreeViewItems(songs);
                }
            }
        }

        private void filterByRating()
        {
            List<mVids.musicVideo> list = this.db.getSongs();
            List<mVids.musicVideo> songs = new List<mVids.musicVideo>();
            string str = this.filterSelectBox.SelectedItem.ToString();
            if (str != null)
            {
                if (!(str == "="))
                {
                    if (str == "Contains")
                    {
                        foreach (mVids.musicVideo video in list)
                        {
                            if (video.rating.Contains(this.filterTextBox.Text))
                            {
                                songs.Add(video);
                            }
                        }
                        this.loadTreeViewItems(songs);
                    }
                }
                else
                {
                    foreach (mVids.musicVideo video in list)
                    {
                        if (video.rating == this.filterTextBox.Text)
                        {
                            songs.Add(video);
                        }
                    }
                    this.loadTreeViewItems(songs);
                }
            }
        }

        private void filterByScore()
        {
            List<mVids.musicVideo> list = this.db.getSongs();
            List<mVids.musicVideo> songs = new List<mVids.musicVideo>();
            string str = this.filterSelectBox.SelectedItem.ToString();
            if (str != null)
            {
                if (!(str == "="))
                {
                    if (str == "Contains")
                    {
                        foreach (mVids.musicVideo video in list)
                        {
                            if (video.score.Contains(this.filterTextBox.Text))
                            {
                                songs.Add(video);
                            }
                        }
                        this.loadTreeViewItems(songs);
                    }
                }
                else
                {
                    foreach (mVids.musicVideo video in list)
                    {
                        if (video.score == this.filterTextBox.Text)
                        {
                            songs.Add(video);
                        }
                    }
                    this.loadTreeViewItems(songs);
                }
            }
        }

        private void filterBySong()
        {
            List<mVids.musicVideo> list = this.db.getSongs();
            List<mVids.musicVideo> songs = new List<mVids.musicVideo>();
            string str = this.filterSelectBox.SelectedItem.ToString();
            if (str != null)
            {
                if (!(str == "="))
                {
                    if (str == "Contains")
                    {
                        foreach (mVids.musicVideo video in list)
                        {
                            if (video.Label.Contains(this.filterTextBox.Text))
                            {
                                songs.Add(video);
                            }
                        }
                        this.loadTreeViewItems(songs);
                    }
                }
                else
                {
                    foreach (mVids.musicVideo video in list)
                    {
                        if (video.Label == this.filterTextBox.Text)
                        {
                            songs.Add(video);
                        }
                    }
                    this.loadTreeViewItems(songs);
                }
            }
        }

        private void filterBySummary()
        {
            List<mVids.artist> list = this.db.getArtistsAndBios(true);
            List<mVids.artist> artists = new List<mVids.artist>();
            string str = this.filterSelectBox.SelectedItem.ToString();
            if (str != null)
            {
                if (!(str == "="))
                {
                    if (str == "Contains")
                    {
                        artists = new List<mVids.artist>();
                        foreach (mVids.artist artist in list)
                        {
                            if (artist.bio.Contains(this.filterTextBox.Text))
                            {
                                artists.Add(artist);
                            }
                        }
                        this.loadTreeViewItems(artists, false);
                    }
                }
                else
                {
                    artists = new List<mVids.artist>();
                    foreach (mVids.artist artist in list)
                    {
                        if (artist.bio == this.filterTextBox.Text)
                        {
                            artists.Add(artist);
                        }
                    }
                    this.loadTreeViewItems(artists, false);
                }
            }
        }

        private void filterByTags()
        {
            List<string> list = this.db.getArtists();
            List<mVids.artist> artists = new List<mVids.artist>();
            string str2 = this.filterSelectBox.SelectedItem.ToString();
            if (str2 != null)
            {
                mVids.artistInfo info;
                mVids.artist artist;
                if (!(str2 == "="))
                {
                    if (str2 == "Contains")
                    {
                        foreach (string str in list)
                        {
                            info = this.db.getArtistInfo(str);
                            if (info.tags.Contains(this.filterTextBox.Text))
                            {
                                artist = new mVids.artist {
                                    artistName = str,
                                    bio = info.bioSummary
                                };
                                artists.Add(artist);
                            }
                        }
                        this.loadTreeViewItems(artists, false);
                    }
                }
                else
                {
                    foreach (string str in list)
                    {
                        info = this.db.getArtistInfo(str);
                        if (info.tags == this.filterTextBox.Text)
                        {
                            artist = new mVids.artist {
                                artistName = str,
                                bio = info.bioSummary
                            };
                            artists.Add(artist);
                        }
                    }
                    this.loadTreeViewItems(artists, false);
                }
            }
        }

        private void imageContext_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            string text = e.ClickedItem.Text;
            if (text != null)
            {
                if (!(text == "Import Artist Image"))
                {
                    if (text == "Regrab Video Thumbnail")
                    {
                        new mVids.thumbDlg(this.pictureBox1.ImageLocation, this.currFilename).ShowDialog();
                        this.pictureBox1.ImageLocation = this.thumbdir + @"\mvids\Videos\" + this.currFilename.Remove(0, this.currFilename.LastIndexOf(@"\") + 1) + ".jpg";
                    }
                }
                else
                {
                    this.openFileDialog1.ShowDialog();
                    if ((this.openFileDialog1.FileName.Length > 0) && File.Exists(this.openFileDialog1.FileName))
                    {
                        File.Copy(this.openFileDialog1.FileName, this.thumbdir + @"\mvids\Artists\" + this.currArtist + ".jpg", true);
                    }
                    this.pictureBox1.ImageLocation = this.thumbdir + @"\mvids\Artists\" + this.currArtist + ".jpg";
                }
            }
        }

        private void InitializeComponent()
        {
            this.components = new Container();
            this.treeView1 = new TreeView();
            this.imageContext = new ContextMenuStrip(this.components);
            this.openFileDialog1 = new OpenFileDialog();
            this.menuStrip1 = new MenuStrip();
            this.addManualToolStripMenuItem = new ToolStripMenuItem();
            this.button2 = new Button();
            this.filterTextBox = new TextBox();
            this.label9 = new Label();
            this.filterFieldbox = new ComboBox();
            this.filterSelectBox = new ComboBox();
            this.showAllbtn = new Button();
            this.detailsPanel = new Panel();
            this.pictureBox2 = new PictureBox();
            this.pictureBox1 = new PictureBox();
            this.menuStrip1.SuspendLayout();
            ((ISupportInitialize) this.pictureBox2).BeginInit();
            ((ISupportInitialize) this.pictureBox1).BeginInit();
            base.SuspendLayout();
            this.treeView1.Anchor = AnchorStyles.Right | AnchorStyles.Left;
            this.treeView1.Location = new Point(6, 0x23);
            this.treeView1.Name = "treeView1";
            this.treeView1.Size = new Size(0xdd, 0x223);
            this.treeView1.TabIndex = 0;
            this.treeView1.AfterSelect += new TreeViewEventHandler(this.treeView1_AfterSelect);
            this.imageContext.Name = "contextMenuStrip1";
            this.imageContext.Size = new Size(0x3d, 4);
            this.imageContext.ItemClicked += new ToolStripItemClickedEventHandler(this.imageContext_ItemClicked);
            this.openFileDialog1.Filter = "JPG Image|*.jpg";
            this.openFileDialog1.Title = "Select Artist Image";
            this.menuStrip1.Items.AddRange(new ToolStripItem[] { this.addManualToolStripMenuItem });
            this.menuStrip1.Location = new Point(0, 0);
            this.menuStrip1.Name = "menuStrip1";
            this.menuStrip1.RenderMode = ToolStripRenderMode.System;
            this.menuStrip1.Size = new Size(940, 0x18);
            this.menuStrip1.TabIndex = 0x25;
            this.menuStrip1.Text = "menuStrip1";
            this.addManualToolStripMenuItem.Name = "addManualToolStripMenuItem";
            this.addManualToolStripMenuItem.Size = new Size(0x54, 20);
            this.addManualToolStripMenuItem.Text = "Add Manual";
            this.addManualToolStripMenuItem.Click += new EventHandler(this.addManualToolStripMenuItem_Click);
            this.button2.Location = new Point(800, 0x9b);
            this.button2.Name = "button2";
            this.button2.Size = new Size(0x4b, 0x45);
            this.button2.TabIndex = 0x2b;
            this.button2.Text = "Update Artist Info from last.fm";
            this.button2.UseVisualStyleBackColor = true;
            this.button2.Click += new EventHandler(this.button2_Click);
            this.filterTextBox.Location = new Point(0x341, 3);
            this.filterTextBox.Name = "filterTextBox";
            this.filterTextBox.Size = new Size(100, 20);
            this.filterTextBox.TabIndex = 0x2c;
            this.filterTextBox.TextChanged += new EventHandler(this.filter_changed);
            this.label9.AutoSize = true;
            this.label9.BackColor = Color.Transparent;
            this.label9.Location = new Point(0x217, 6);
            this.label9.Name = "label9";
            this.label9.Size = new Size(100, 13);
            this.label9.TabIndex = 0x2d;
            this.label9.Text = "Show videos where";
            this.filterFieldbox.FormattingEnabled = true;
            this.filterFieldbox.Items.AddRange(new object[] { "Artist", "Song", "Filename", "Rating", "Play Count", "Score", "Length", "Biography (Summary)", "Biography (Full)", "Tags" });
            this.filterFieldbox.Location = new Point(0x281, 2);
            this.filterFieldbox.Name = "filterFieldbox";
            this.filterFieldbox.Size = new Size(0x6f, 0x15);
            this.filterFieldbox.TabIndex = 0x2e;
            this.filterFieldbox.SelectedIndexChanged += new EventHandler(this.filter_changed);
            this.filterSelectBox.FormattingEnabled = true;
            this.filterSelectBox.Items.AddRange(new object[] { "=", "Contains" });
            this.filterSelectBox.Location = new Point(0x2f6, 2);
            this.filterSelectBox.Name = "filterSelectBox";
            this.filterSelectBox.Size = new Size(0x45, 0x15);
            this.filterSelectBox.TabIndex = 0x2f;
            this.filterSelectBox.SelectedIndexChanged += new EventHandler(this.filter_changed);
            this.showAllbtn.Location = new Point(0x1ef, 0);
            this.showAllbtn.Name = "showAllbtn";
            this.showAllbtn.Size = new Size(0x20, 0x17);
            this.showAllbtn.TabIndex = 0x30;
            this.showAllbtn.Text = "All";
            this.showAllbtn.UseVisualStyleBackColor = true;
            this.showAllbtn.Click += new EventHandler(this.showAllbtn_Click);
            this.detailsPanel.BorderStyle = BorderStyle.FixedSingle;
            this.detailsPanel.Location = new Point(0xe9, 0xe8);
            this.detailsPanel.Name = "detailsPanel";
            this.detailsPanel.Size = new Size(700, 350);
            this.detailsPanel.TabIndex = 0x31;
            this.pictureBox2.Image = mVids.Properties.Resources.mvids_logo;
            this.pictureBox2.Location = new Point(0x341, 0x1d);
            this.pictureBox2.Name = "pictureBox2";
            this.pictureBox2.Size = new Size(100, 40);
            this.pictureBox2.SizeMode = PictureBoxSizeMode.AutoSize;
            this.pictureBox2.TabIndex = 50;
            this.pictureBox2.TabStop = false;
            this.pictureBox1.Anchor = AnchorStyles.Right | AnchorStyles.Left;
            this.pictureBox1.BorderStyle = BorderStyle.FixedSingle;
            this.pictureBox1.ContextMenuStrip = this.imageContext;
            this.pictureBox1.Location = new Point(440, 0x2a);
            this.pictureBox1.Name = "pictureBox1";
            this.pictureBox1.Size = new Size(0x144, 0xb6);
            this.pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
            this.pictureBox1.TabIndex = 1;
            this.pictureBox1.TabStop = false;
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.ClientSize = new Size(940, 0x254);
            base.Controls.Add(this.showAllbtn);
            base.Controls.Add(this.filterSelectBox);
            base.Controls.Add(this.detailsPanel);
            base.Controls.Add(this.filterFieldbox);
            base.Controls.Add(this.label9);
            base.Controls.Add(this.filterTextBox);
            base.Controls.Add(this.pictureBox2);
            base.Controls.Add(this.button2);
            base.Controls.Add(this.menuStrip1);
            base.Controls.Add(this.treeView1);
            base.Controls.Add(this.pictureBox1);
            base.MainMenuStrip = this.menuStrip1;
            base.MaximizeBox = false;
            base.Name = "dbManager";
            base.SizeGripStyle = SizeGripStyle.Hide;
            this.Text = "dbManager";
            base.Load += new EventHandler(this.dbManager_Load);
            this.menuStrip1.ResumeLayout(false);
            this.menuStrip1.PerformLayout();
            ((ISupportInitialize) this.pictureBox2).EndInit();
            ((ISupportInitialize) this.pictureBox1).EndInit();
            base.ResumeLayout(false);
            base.PerformLayout();
        }

        private void loadTreeViewItems(List<mVids.musicVideo> songs)
        {
            this.treeView1.Nodes.Clear();
            for (int i = 0; i < songs.Count; i++)
            {
                TreeNode node = new TreeNode {
                    Text = songs[i].artist + " - " + songs[i].Label,
                    Tag = songs[i].Path
                };
                if (!File.Exists(this.thumbdir + @"\mvids\Videos\" + node.Tag.ToString().Remove(0, node.Tag.ToString().LastIndexOf(@"\") + 1) + ".jpg"))
                {
                    node.ForeColor = Color.Red;
                }
                this.treeView1.Nodes.Add(node);
            }
        }

        private void loadTreeViewItems(List<mVids.artist> artists, bool getAll)
        {
            this.treeView1.Nodes.Clear();
            if (getAll)
            {
                artists = this.db.getArtistsAndBios(true);
            }
            Log.Info("Music Video DB - Found {0} artists in DB", new object[] { artists.Count.ToString() });
            for (int i = 0; i < artists.Count; i++)
            {
                TreeNode node = new TreeNode {
                    Text = artists[i].artistName
                };
                if (((artists[i].bio == "") || !File.Exists(this.thumbdir + @"\mvids\Artists\" + node.Text + ".jpg")) || (this.db.getArtistInfo(node.Text).tags == ""))
                {
                    node.ForeColor = Color.Red;
                }
                List<mVids.musicVideo> list = this.db.getFilesByArtist(artists[i].artistName);
                foreach (mVids.musicVideo video in list)
                {
                    TreeNode node2 = new TreeNode {
                        Text = video.Label,
                        Tag = video.Path
                    };
                    if (!File.Exists(this.thumbdir + @"\mvids\Videos\" + node2.Tag.ToString().Remove(0, node2.Tag.ToString().LastIndexOf(@"\") + 1) + ".jpg"))
                    {
                        node.ForeColor = Color.Red;
                        node2.ForeColor = Color.Red;
                    }
                    node.Nodes.Add(node2);
                }
                this.treeView1.Nodes.Add(node);
            }
        }

        private void pictureBox1_DragDrop(object sender, DragEventArgs e)
        {
            foreach (string str in e.Data.GetFormats())
            {
                Log.Debug("format " + str, new object[0]);
            }
        }

        private void pictureBox1_DragEnter(object sender, DragEventArgs e)
        {
            e.Effect = DragDropEffects.Copy;
        }

        private void setupArtist(string artist)
        {
            this.currArtist = artist;
            this.button2.Enabled = true;
            this.clearFields(true);
            mVids.artistInfo info = this.db.getArtistInfo(artist);
            mVids.artistUC tuc = new mVids.artistUC(this.db, artist, info.lfmName, info.tags, info.bioSummary, info.bioContent);
            this.detailsPanel.Controls.Clear();
            this.detailsPanel.Controls.Add(tuc);
            tuc.Disposed += new EventHandler(this.aUC_Disposed);
            this.pictureBox1.ImageLocation = this.thumbdir + @"\mvids\Artists\" + artist + ".jpg";
        }

        private void setupSong(string song, string artist, string filename)
        {
            this.button2.Enabled = false;
            this.clearFields(false);
            List<string> list = this.db.getSongInfo(filename);
            this.currFilename = filename;
            mVids.videoUC ouc = new mVids.videoUC(this.db, artist, this.db.getArtists(), song, filename, list[1], list[0], list[3], list[2]);
            this.detailsPanel.Controls.Clear();
            this.detailsPanel.Controls.Add(ouc);
            ouc.Disposed += new EventHandler(this.aUC_Disposed);
            this.pictureBox1.ImageLocation = this.thumbdir + @"\mvids\Videos\" + filename.Remove(0, filename.LastIndexOf(@"\") + 1) + ".jpg";
        }

        private void showAllbtn_Click(object sender, EventArgs e)
        {
            try
            {
                this.filterFieldbox.SelectedItem = null;
                this.filterSelectBox.SelectedItem = null;
                this.filterTextBox.Text = "";
                this.loadTreeViewItems(new List<mVids.artist>(), true);
            }
            catch
            {
            }
        }

        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if ((e.Node.Level == 0) && (e.Node.Tag == null))
            {
                this.setupArtist(e.Node.Text);
            }
            else if ((e.Node.Level == 0) && (e.Node.Tag != null))
            {
                this.setupSong(e.Node.Text, null, e.Node.Tag.ToString());
            }
            else
            {
                this.setupSong(e.Node.Text, e.Node.Parent.Text, e.Node.Tag.ToString());
            }
        }
    }
}

